// ReplyMailListener.java
package com.sky.listener;

import com.sky.constant.EmailConstant;
import com.sky.event.ReplyCreatedEvent;
import com.sky.service.EmailService; // 你已有发送能力
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class ReplyMailListener {

    private final EmailService emailService;

    @Async   // 异步发送
    @EventListener //事件监听
    public void handle(ReplyCreatedEvent event) {
        String subject = EmailConstant.EMAIL_REPLY_SUBJECT;
        String body = String.format(EmailConstant.EMAIL_REPLY_BODY,
                event.getReplierNick(),
                event.getContent());

        // 发送邮件
        emailService.sendTextMail(event.getTargetEmail(), subject, body);
    }
}